<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>css表格</title>
  <link rel="stylesheet" href="global.css">
  <style>
    html,
    body {
      height: 100%;
    }

    body {
      margin: 0;
      background: linear-gradient(45deg, #49a09d, #5f2c82);
      font-family: sans-serif;
      font-weight: 100;
    }

    /* 相对body绝对定位居中 */
    .container {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }

    table {
      width: 800px;
      /* 合并边框 */
      border-collapse: collapse;
      overflow: hidden;
      box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    }

    th,
    td {
      padding: 15px;
      background-color: rgba(255, 255, 255, 0.2);
      color: #fff;
    }

    th {
      text-align: left;
    }

    thead th {
      background-color: #55608f;
    }

    /* 表格行鼠标悬浮高亮 */
    tbody tr:hover {
      background-color: rgba(255, 255, 255, 0.3);
    }

    /* 子元素需要根据表格单元绝对定位 */
    tbody td {
      position: relative;
    }

    /* top: -9999px;bottom: -9999px; 模拟列的占位*/
    tbody td:hover::before {
      content: "";
      position: absolute;
      left: 0;
      right: 0;
      top: -9999px;
      bottom: -9999px;
      background-color: rgba(255, 255, 255, 0.2);
      z-index: -1;
    }
  </style>
</head>

<body>
  <header>
    <a href="https://codepen.io/alexerlandsson/pen/mPWgpO">来源点这里</a>
  </header>
  <div class="container">
    <table>
      <thead>
        <tr>
          <th>Column 1</th>
          <th>Column 2</th>
          <th>Column 3</th>
          <th>Column 4</th>
          <th>Column 5</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Cell 1</td>
          <td>Cell 2</td>
          <td>Cell 3</td>
          <td>Cell 4</td>
          <td>Cell 5</td>
        </tr>
        <tr>
          <td>Cell 1</td>
          <td>Cell 2</td>
          <td>Cell 3</td>
          <td>Cell 4</td>
          <td>Cell 5</td>
        </tr>
        <tr>
          <td>Cell 1</td>
          <td>Cell 2</td>
          <td>Cell 3</td>
          <td>Cell 4</td>
          <td>Cell 5</td>
        </tr>
        <tr>
          <td>Cell 1</td>
          <td>Cell 2</td>
          <td>Cell 3</td>
          <td>Cell 4</td>
          <td>Cell 5</td>
        </tr>
        <tr>
          <td>Cell 1</td>
          <td>Cell 2</td>
          <td>Cell 3</td>
          <td>Cell 4</td>
          <td>Cell 5</td>
        </tr>
      </tbody>
    </table>
  </div>
</body>

</html>